<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <input type="text" v-model="msg">
        <p>{{msg}}</p>
    </div>
    <script src="../vue.js"></script>
    <script>
        let vm = new Vue({
            el: '#app',
            data: {
                msg: ''
            },
            // 侦听器-当数据变化时，执行对应的代码
            watch: {
                msg(newVal, oldVal) {
                    console.log('newVal:',newVal);
                    console.log('oldVal:',oldVal);
                    // 判断 18以下是未成年人
                    if(newVal > 18) {
                        console.log('你已经是成年人了，可以做成年人做的事情了');
                    }else {
                        console.log('未成年人禁止入内');
                    }
                }
            }
        })
    </script>
</body>
</html>